@extends('admin::metro.vendor.master')

@section('title')
    {{ $title }}
@stop

@section('content')

<!--params: result, table_style-->
<div class="row-fluid">
    <div class="span6">
        @section('add_button')
        {!! Form::operationButton($uri . '/add', 'class="btn btn-primary" id="add"', 'icon-plus-sign', trans('temp.add')) !!}
        @show
    </div>
    <div class="span6">
        @include('vendor.search_form', ['uri' => $uri])
    </div>
</div>
<br/>

<div class="row-fluid">
    <div class="span6">
        {{ trans('temp.total') }}: <span
            class="label label-default">{{ $results->total() }}</span> {{ trans('temp.results') }}
    </div>
    <div class="span6 pagination-right dataTables_paginate paging_bootstrap pagination">
        @include('admin::metro.vendor._items_per_page')
        <?php echo $results->render() ?>
    </div>
</div>
<div class="table-responsive">
    {!! Form::open() !!}
        <input type="hidden" name="_method" value="PUT" />
        <table class="table table-condensed table-striped">
            <thead>
            @include('admin::metro.permissions._all_thead')
            </thead>
            <?php $permissionIds = array(); ?>
            @foreach($results as $action)
            <tr>
                <td>{{ $action->name }}</td>
                <td title="{{ $action->action }}">
                        {{ str_limit(str_replace('App\\Modules\\','',$action->action), $limit = 50, $end = '...') }}
                    </a>
                </td>
                @foreach($action->permissions as $permission)
                <td>
                    <input type="checkbox" name="permissions[{{ $permission->id }}]" {{ ($permission->allow) ? 'checked' : null }} />
                </td>
                <?php array_push($permissionIds, $permission->id); ?>
                @endforeach
            </tr>
            @endforeach
        </table>

        <hr />
        <input type="hidden" value="{{ implode(',',$permissionIds) }}" name="permission_ids">
        {!! Form::submitButton(trans('temp.save'), 'icon-save', 'class = "btn btn-primary pull-right"') !!}
    <br/>
    {!! Form::close() !!}
</div>
<hr/>
<div class="row-fluid">
    <div class="span6">
        {{ trans('temp.total') }}: <span
            class="label label-default">{{ $results->total() }}</span> {{ trans('temp.results') }}
    </div>
    <div class="span6 pagination-right dataTables_paginate paging_bootstrap pagination">
        <?php echo $results->render() ?>
    </div>
</div>
@stop

@section('javascripts')
    <script type="text/javascript" src="{{ asset('select2/select2.min.js') }}"></script>
<script type="text/javascript">
    $(document).ready(function () {
        // Submit the limit per page form
        $('select[name="limit"]').on('change', function () {
            var form = $(this).parents('form');
            window.location = '{{URL::to($uri . (isset($search) ? "/search" : "/all"))}}' + '?limit=' + $(this).val() + '&param={{ $param }}&order=' + '{{ $order }}{{ isset($search) ? "&search=".$search : "" }}';
        });
    });
</script>
    <script type="text/javascript" src="{{ asset('js/search.js') }}"></script>
@stop